package com.ict.web.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.core.domain.entity.SysUser;
import com.ict.common.utils.DictUtils;
import com.ict.common.utils.SecurityUtils;
import com.ict.common.utils.StringUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.system.service.ISysDictDataService;
import com.ict.system.service.ISysUserService;
import com.ict.web.constant.Constants;
import com.ict.web.constant.ProjectStatusEnum;
import com.ict.web.domain.*;
import com.ict.web.dto.*;
import com.ict.web.mapper.*;
import com.ict.web.service.*;
import com.ict.web.utils.pdf.RoleUtil;
import com.ict.web.vo.*;
import io.jsonwebtoken.lang.Assert;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 抽取规则Service业务层处理
 *
 * @author xc
 * @date 2022-02-25
 */
@Service
public class ExtractRuleServiceImpl extends ServiceImpl<ExtractRuleMapper, ExtractRule> implements IExtractRuleService
{
    @Autowired
    private ExtractRuleMapper extractRuleMapper;
    @Autowired
    private IExpertInformationSheetService expertInformationSheetService;
    @Autowired
    private ExpertInformationSheetMapper expertInformationSheetMapper;
    @Autowired
    private IExtractExpertService extractExpertService;
    @Autowired
    private IReviewTaskService reviewTaskService;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private IExtractReviewService extractReviewService;
    @Autowired
    private OrganizationManagementMapper organizationManagementMapper;
    @Autowired
    private IExpertRuleDescService expertRuleDescService;
    @Autowired
    private ReviewTaskMapper reviewTaskMapper;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private IApprovalService approvalService;
    @Autowired
    private IProjectManagementService projectManagementService;
    @Autowired
    private IExpertCourseService expertCourseService;
    @Autowired
    private IExtractRuleService extractRuleService;
    @Autowired
    private IOrganizationManagementService organizationManagementService;
    @Autowired
    private ExtractMonitoringMapper extractMonitoringMapper;
    /**
     * 查询抽取出来的专家信息和该规则信息
     *
     * @param list 抽取规则
     * @return ExtractRuleBeginVo
     */
    @Override
    public List<ExtractRuleBeginVo> selectExtractRuleList(List<ExtractRuleBeginDto> list)
    {
        Assert.isTrue(!Collections.isEmpty(list),"最少添加一条抽取规则");
        Integer sum = list.stream().mapToInt(ExtractRuleBeginDto::getPeopleNumber).sum();
        Assert.isTrue(sum<=10,"抽取人数最多为10人");
        List<ExtractRuleBeginVo> extractRuleBeginVoList = new ArrayList<>();
        HashMap<Long, Object> map = new HashMap<>();
        //抽取类型排序 ：指定-条件-随机
        list = sort(list);
        //抽取出的专家id
        List<Long> idList = new ArrayList<>();
        //已抽取专家id
        List<Long> collectExtractId = new ArrayList<>();
        //根据登录信息确认三方机构或大数据
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        LambdaQueryWrapper<OrganizationManagement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrganizationManagement::getDeptId,deptId);
        OrganizationManagement organizationManagement = organizationManagementMapper.selectOne(queryWrapper);

        QueryWrapper<ExpertInformationSheet> expertInformationSheetQueryWrapper = new QueryWrapper<>();
        expertInformationSheetQueryWrapper.eq("del_flag","0");
        List<ExpertInformationSheet> expertInformationSheetList = expertInformationSheetMapper.selectList(expertInformationSheetQueryWrapper);

        list.forEach(s->{

            Long ormId = null;
            List<Long> expertIds = null;
            if (StringUtils.isNotNull(organizationManagement)) {
                ormId = organizationManagement.getOrmId();
            }else {
                expertIds = expertInformationSheetList.stream().map(ExpertInformationSheet::getExpertId).collect(Collectors.toList());
            }

            if(ExtractRule.EXTRACT_TYPE_APPOINT.equals(s.getExtractType())){
                Assert.isTrue(!Collections.isEmpty(s.getExpertIdList()),"指定抽取专家信息为空");
                Assert.isTrue(s.getPeopleNumber().equals(s.getExpertIdList().size()),"指定专家人数有误！");
                dealVo(collectExtractId,s.getExpertIdList(),s,extractRuleBeginVoList,s.getExtractType(),null);
            }else if(ExtractRule.EXTRACT_TYPE_CONDITION.equals(s.getExtractType())){
                List<Long> conditionSelectIds
                        = expertInformationSheetService.conditionSelect(s.getExpertInformationSheet(),collectExtractId);
                Assert.isTrue(!Collections.isEmpty(conditionSelectIds),"条件抽取未找到该专家信息");
                Assert.isTrue(s.getPeopleNumber()<=(conditionSelectIds.size()),"条件抽取人数不足");
                List<Long> resultList = getRandomThreeInfoList(conditionSelectIds, s.getPeopleNumber());
                //处理返回vo
                dealVo(collectExtractId,resultList,s,extractRuleBeginVoList,s.getExtractType(),s.getExpertInformationSheet());
            }else {
                if (StringUtils.isNotNull(expertIds)) {
                    Assert.isTrue(s.getPeopleNumber()<=(expertIds.size()),"随机人数不足");
                }
                List<Long> randomOneId = expertInformationSheetService.selectRandomOne(String.valueOf(s.getPeopleNumber()),ormId,expertIds,collectExtractId);
                Assert.isTrue(StringUtils.isNotNull(randomOneId),"随机抽取未找到该专家信息");
                dealVo(collectExtractId,randomOneId,s,extractRuleBeginVoList,s.getExtractType(),null);
            }
        });
        return extractRuleBeginVoList;
    }

    /**指定-条件-随机*/
    private List<ExtractRuleBeginDto> sort(List<ExtractRuleBeginDto> list){
        List<String> sortList = Arrays.asList("3", "1", "2");
        return list.stream().sorted(
                Comparator.comparing(ExtractRuleBeginDto::getExtractType, (x, y) -> {
                    //按照读取的list顺序排序
                    for (String sort : sortList) {
                        if (sort.equals(x) || sort.equals(y)) {
                            if (x.equals(y)) {
                                return 0;
                            } else if (sort.equals(x)) {
                                return -1;
                            } else {
                                return 1;
                            }
                        }
                    }
                    return 0;
                })
        ).collect(Collectors.toList());
    }

    /**
     * 处理返回vo
     * @param idList 抽取出的专家idlist
     * @param collectExtractId 已抽取出的专家idlist
     * @param dto
     * @param extractRuleBeginVoList 返回vo
     * @param expertInformationSheet 条件抽取专家的筛选条件
     */
    public void dealVo(List<Long> collectExtractId, List<Long> idList, ExtractRuleBeginDto dto, List<ExtractRuleBeginVo> extractRuleBeginVoList, String type, ExpertInformationSheetDto expertInformationSheet){
        List<ExtractRuleBeginVo> extractRuleBeginVos = expertInformationSheetService.selectListById(idList);
        //去掉重复数据
        for (int i = 0; i <idList.size() ; i++) {
            if (collectExtractId.contains(idList.get(i))){
                idList.remove(idList.get(i));
            }
        }
        String extractType = DictUtils.getDictLabel("extract_type", type);
        Assert.isTrue(!Collections.isEmpty(idList),extractType+"未找到该类型专家信息");
        //重复性校验和人数校验
        ExtractRuleEditDto extractRuleEditDto = new ExtractRuleEditDto(dto.getPeopleNumber());
        check(idList,extractRuleEditDto,collectExtractId,extractType);
        //放入已存抽取专家idlist
        collectExtractId.addAll(idList);
        Long extractId = IdUtils.snowId();
        extractRuleBeginVos.forEach(a->{
            a.setMajor(dictDataService.selectDictLabel("major",a.getMajor()));
            a.setEducation(dictDataService.selectDictLabel("education_background",a.getEducation()));
            a.setAreasOfExpertise(dictDataService.selectDictLabel("areas_of_expertise",a.getAreasOfExpertise()));
            a.setExtractRuleId(extractId);
            a.setExtractRuleDesc(dto.getExtractRuleDesc());
            a.setExtractType(dto.getExtractType());
            a.setPeopleNumber(dto.getPeopleNumber());
            //技术职称
            List<TechnicalTitle> technicalName = a.getTechnicalTitles();
            if(StringUtils.isNotEmpty(technicalName)){
            List<String> technicalCollect = technicalName.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());
                List<String> technicalList = new ArrayList<>();
                technicalCollect.stream().forEach(s->{
                    technicalList.add(dictDataService.selectDictLabel("technical_type", s));
            });
                a.setTechnicalTitlesName(StringUtils.join(technicalList,","));
            }
            //职业资格
            List<ProfessionalQualification> qualificationList = a.getQualifications();
            if(StringUtils.isNotEmpty(qualificationList)) {
                List<String> qualificationCollect = qualificationList.stream().map(ProfessionalQualification::getQualificationName).collect(Collectors.toList());
                List<String> qualificationNameList = new ArrayList<>();
                qualificationCollect.stream().forEach(s->{
                    qualificationNameList.add(dictDataService.selectDictLabel("professional_type", s));
                });
                a.setQualificationsName(StringUtils.join(qualificationNameList,","));
            }
            extractRuleBeginVoList.add(a);
        });
        //新增条件抽取的筛选条件
        if(StringUtils.isNotNull(expertInformationSheet)){
            ExpertRuleDesc expertRuleDesc = new ExpertRuleDesc();
            expertRuleDesc.setExpertRuleDescId(IdUtils.snowId());
            expertRuleDesc.setPoliticalOutLook(expertInformationSheet.getPoliticalOutlook()!=null?expertInformationSheet.getPoliticalOutlook():null);
            expertRuleDesc.setSex(expertInformationSheet.getSex()!=null?expertInformationSheet.getSex():null);
            expertRuleDesc.setExtractId(extractId);
            expertRuleDesc.setEndAge(expertInformationSheet.getEndAge()!=null?expertInformationSheet.getEndAge():null);
            expertRuleDesc.setStartAge(expertInformationSheet.getStartAge()!=null?expertInformationSheet.getStartAge():null);
            expertRuleDesc.setEqualAge(expertInformationSheet.getEqualAge()!=null?expertInformationSheet.getEqualAge():null);
            List<String> areasOfExpertiseList = expertInformationSheet.getAreasOfExpertise();
            if(StringUtils.isNotEmpty(areasOfExpertiseList)){
                String areasOfExpertise = areasOfExpertiseList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
                expertRuleDesc.setAreasOfExpertise(areasOfExpertise);
            }
            List<String> majorList = expertInformationSheet.getMajor();
            if(StringUtils.isNotEmpty(majorList)){
                String major = majorList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
                expertRuleDesc.setMajor(major);
            }
            List<String> technicalTitlesList = expertInformationSheet.getTechnicalTitles();
            if(StringUtils.isNotEmpty(technicalTitlesList)){
                String technicalTitles = technicalTitlesList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
                expertRuleDesc.setTechnicalTitles(technicalTitles);
            }
            List<String> qualificationsList = expertInformationSheet.getQualifications();
            if(StringUtils.isNotEmpty(qualificationsList)){
                String qualifications = qualificationsList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
                expertRuleDesc.setQualifications(qualifications);
            }
            expertRuleDescService.save(expertRuleDesc);
        }
    }
    /**
     * 在list集合中随机取出指定数量的元素
     * @param list 取元素的集合
     * @param count 个数
     * @return
     */
    public static List<Long> getRandomThreeInfoList(List<Long> list, int count) {
        List<Long> olist = new ArrayList<>();
        if (list.size() <= count) {
            return list;
        } else {
            Random random = new Random();
            for (int i = 0 ;i<count;i++){
                int intRandom = random.nextInt(list.size() - 1);
                olist.add(list.get(intRandom));
                list.remove(list.get(intRandom));
            }
            return olist;
        }
    }
    /**
     * 修改抽取规则
     *
     * @param dto 抽取规则
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public long updateExtractRule(ExtractRuleEditDto dto) {
        Assert.isTrue(StringUtils.isNotNull(dto.getExtractRuleId()),"规则表id不能为空");
        ExtractRule extractRule = extractRuleMapper.selectById(dto.getExtractRuleId());
        //todo 抽取规则修改，删除该规则下原抽取专家数据，根据新规则抽取专家信息并更新评审任务专家数量
        BeanUtils.copyProperties(dto,extractRule);
        extractRule.setUpdateTime(LocalDateTime.now());
        extractRuleMapper.updateById(extractRule);

        //已经抽取专家信息 避免重复
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(dto.getReviewTaskId());
        List<ExtractExpertDetailVo> extractionList = reviewTaskDetailVo.getExtractExpertList();
        List<Long> collectExtractId = extractionList.stream().filter(
                s -> !s.getExtractRuleId().equals(extractRule.getExtractId())).map(ExtractExpertDetailVo::getExpertId).collect(Collectors.toList());
        //删除原抽取专家信息，根据规则重新抽取
        HashMap<String, Object> map = new HashMap<>();
        map.put("extract_rule_id",extractRule.getExtractId());
        List<Long> removeIdList = extractExpertService.listByMap(map).stream().map(ExtractExpert::getExtractExpertId).collect(Collectors.toList());
        extractExpertService.removeByIds(removeIdList);
        //删除评审任务与抽取的专家关联信息
        QueryWrapper<ExtractReview> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("extract_expert_id",removeIdList);
        extractReviewService.remove(queryWrapper);
        List<ExtractExpert> extractExpertList = new ArrayList<>();
        List<Long> idList = new ArrayList<>();
        List<Long> extractExpertIdList = new ArrayList<>();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        //根据规则类型抽取专家id
        extractExpertByRule(extractRule,dto,sysUser,collectExtractId,idList);
        //初始化抽取出专家的信息
        idList.forEach(s->{
            ExtractExpert extractExpert = new ExtractExpert();
            extractExpert.setExtractExpertId(IdUtils.snowId());
            extractExpert.setExpertId(s);
            extractExpert.setExtractNode(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode());
            //年度清单评审任务节点直接是现场论证
            if(reviewTaskDetailVo.getReviewType().equals(ReviewTask.REVIEW_TYPE_ANNUAL)){
                extractExpert.setExtractNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
            }
            extractExpert.setExtractRuleId(dto.getExtractRuleId());
            extractExpert.setStatus(ExtractExpert.STATUS_NOT_ACCEPT);
            extractExpert.setDelFlag(ExtractExpert.DELETE_STATUS_NORMAL);
            extractExpert.setCreateTime(LocalDateTime.now());
            extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_TO_BE_ACCEPT);
            extractExpert.setApplyCancel(ExtractExpert.APPLY_NOT_CANCEL);
            extractExpertList.add(extractExpert);
            extractExpertIdList.add(extractExpert.getExtractExpertId());
        });
        extractExpertService.batchInsertExtractExpert(extractExpertList);
        //更新评审任务专家数量
        int peopleNumber = reviewTaskDetailVo.getExtractRuleList().stream().mapToInt(ExtractRule::getPeopleNumber).sum();
        ReviewTask reviewTask = reviewTaskService.getById(dto.getReviewTaskId());
        reviewTask.setExpertNum(String.valueOf(peopleNumber));
        reviewTaskService.updateById(reviewTask);
        //更新评审任务与抽取的专家关系表
        extractReviewService.batchInsertExtractReview(dto.getReviewTaskId(),extractExpertIdList);
        return extractRule.getExtractId();
    }

    /**
     *  根据规则抽取专家
     * @param extractRule 规则
     * @param dto 抽取参数对象
     * @param sysUser
     * @param collectExtractId  已抽取的专家idList
     * @param idList  抽取的idList
     */
    public void extractExpertByRule(ExtractRule extractRule,ExtractRuleEditDto dto,SysUser sysUser,List<Long> collectExtractId,List<Long> idList){
        String extractType = DictUtils.getDictLabel("extract_type", extractRule.getExtractType());

        //根据登录信息确认三方机构或大数据
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        LambdaQueryWrapper<OrganizationManagement> organizationQueryWrapper = new LambdaQueryWrapper<>();
        organizationQueryWrapper.eq(OrganizationManagement::getDeptId,deptId);
        OrganizationManagement organizationManagement = organizationManagementMapper.selectOne(organizationQueryWrapper);

        QueryWrapper<ExpertInformationSheet> expertInformationSheetQueryWrapper = new QueryWrapper<>();
        expertInformationSheetQueryWrapper.isNull("orm_id").eq("del_flag","0");
        List<ExpertInformationSheet> expertInformationSheetList = expertInformationSheetMapper.selectList(expertInformationSheetQueryWrapper);

        switch (extractRule.getExtractType()){
            case ExtractRule.EXTRACT_TYPE_CONDITION :
                //todo 条件抽取：1.校验抽取出来的结果数量是否大于或等于抽取人数
                //              2.校验抽取出来的专家是否出现重复情况，如重复，未重复的结果数量是否大于或等于抽取人数
                //              3.以上情况都通过，则返回同等抽取人数的结果数量
                ExpertInformationSheet expertInformationSheet = dto.getExpertInformationSheet();
                if(sysUser.getRoleId().equals("104")){
                    expertInformationSheet.setUserId(SecurityUtils.getUserId());
                }

                Long ormId = null;
                List<Long> expertIds = null;

                if (StringUtils.isNotNull(organizationManagement)) {
                    ormId = organizationManagement.getOrmId();
                }else {
                    expertIds = expertInformationSheetList.stream().map(ExpertInformationSheet::getExpertId).collect(Collectors.toList());
                }

                List<ExpertInformationSheetDetailVo> expertInformationSheets
                        = expertInformationSheetService.selectExpertInformationSheetList(expertInformationSheet,ormId,expertIds);
                //条件查询出的专家信息
                List<Long> savaIdList = expertInformationSheets.stream().map(ExpertInformationSheetDetailVo::getExpertId).collect(Collectors.toList());
                //人数校验
                List<Long> rrList = check(savaIdList, dto, collectExtractId,extractType);
                //筛选出指定人数
                List<Long> resultIdList = getRandomThreeInfoList(rrList, dto.getPeopleNumber());
                idList.addAll(resultIdList);
                break;
            case ExtractRule.EXTRACT_TYPE_RANDOM :
                List<ExpertInformationSheet> list ;
                //机构查询专家
                if(sysUser.getRoleId().equals("104")){
                    QueryWrapper<ExpertInformationSheet> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("user_id",SecurityUtils.getUserId());
                    list = expertInformationSheetService.list(queryWrapper);
                }
                //大数据局查询专家
                list = expertInformationSheetService.list(null);
                List<Long> randomOneIdList = list.stream().map(ExpertInformationSheet::getExpertId).collect(Collectors.toList());
                //人数校验
                List<Long> randomrrList = check(randomOneIdList, dto, collectExtractId,extractType);
                //筛选出指定人数
                List<Long> randomrResultIdList = getRandomThreeInfoList(randomrrList, dto.getPeopleNumber());
                idList.addAll(randomrResultIdList);
                break;
            case ExtractRule.EXTRACT_TYPE_APPOINT :
                //人数校验
                List<Long> appointrrList = check(dto.getExpertIdList(), dto, collectExtractId,extractType);
                idList.addAll(appointrrList);
                break;
        }
    }
    /**
     * 人数校验
     * @param idList 抽取出的专家idlist
     * @param dto
     * @param collectExtractId 已抽取出的专家idlist
     */
    public List<Long> check(List<Long> idList,ExtractRuleEditDto dto,List<Long> collectExtractId,String extractType){
        Assert.isTrue(!Collections.isEmpty(idList),extractType+"未找到该类型专家信息");
        Assert.isTrue(idList.size()>=dto.getPeopleNumber(),
                extractType+"：该条件抽取结果数量不满足抽取人数（"+dto.getPeopleNumber()+"人）！请重新更换条件");
        //重复校验后结果
        List<Long> rrList = removeRepetition(collectExtractId, idList);
        Assert.isTrue(rrList.size()>=dto.getPeopleNumber(),
                extractType+"：查询经重复校验，不重复的结果数量不满足抽取人数（"+dto.getPeopleNumber()+"人）！请重新更换条件");
        return rrList;
    }

    /**
     *  去掉重复数据
     * @param poolList  数据池
     * @param checkList 校验的数据
     * @return
     */
    public List<Long>  removeRepetition(List<Long> poolList, List<Long> checkList){
        List<Long> rrList = new ArrayList<>();
        checkList.forEach(s->{
            while (poolList.contains(s)){
                continue;
            }
            rrList.add(s);
        });
        return rrList;
    }
    @Override
    public int batchInsert(List<ExtractRule> list) {
        return extractRuleMapper.batchInsert(list);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ExpertInformationSheetDetailVo updateRuleExchangeExpert(ExchangeExpertDto dto) {
        //为抽取的专家id
        ExtractExpert extractExpert = extractExpertService.getById(dto.getExtractExpertId());
        ExtractRule extractRule = extractRuleMapper.selectById(extractExpert.getExtractRuleId());
        Long expertId=null;
        List<Long> collect =residueExpert(dto);
        //已抽取出的专家id
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(dto.getReviewTaskId());
        List<Long> collectExtractId = reviewTaskDetailVo.getExtractExpertList().stream()
                .map(ExtractExpertDetailVo::getExpertId).collect(Collectors.toList());
        if(ExtractRule.EXTRACT_TYPE_CONDITION.equals(dto.getExtractType())){
            List<Long> conditionSelect = expertInformationSheetService.conditionSelect(dto.getExpertInformationSheet(),collectExtractId);
            Assert.isTrue(StringUtils.isNotEmpty(conditionSelect),"条件查询：未找到该条件下的专家");
            List<Long> expertIdList = getRandomThreeInfoList(conditionSelect, 1);
            Assert.isTrue(StringUtils.isNotEmpty(expertIdList),"从查询结果中未找到该专家");
            expertId = expertIdList.get(0);

        }
        if(ExtractRule.EXTRACT_TYPE_RANDOM.equals(dto.getExtractType())){
            Long deptId = SecurityUtils.getLoginUser().getDeptId();
            List<OrganizationManagement> organizationManagementList = organizationManagementService.lambdaQuery().eq(OrganizationManagement::getDeptId, deptId).list();
            //三方机构条件抽取专家
            Long ormId=null;
            if(StringUtils.isNotEmpty(organizationManagementList)){
                ormId=organizationManagementList.get(0).getOrmId();
            }
            List<Long> randomOneList = expertInformationSheetService.selectRandomOne("1", ormId, collect,collectExtractId);
            Assert.isTrue(StringUtils.isNotEmpty(randomOneList),"随机查询：未找到该条件下的专家");
            expertId = randomOneList.get(0);
        }
        ExpertInformationSheetDetailVo expertInformationSheetDetailVo = new ExpertInformationSheetDetailVo();
        //重新抽取达到3次数返回更换回显的专家信息
        if(extractExpert.getAgainExtractNum().equals("3")){
            List<ExtractMonitoring> extractMonitoringList = extractMonitoringMapper.selectList(new QueryWrapper<ExtractMonitoring>()
                    .eq("extract_expert_id ", extractExpert.getExtractExpertId())
                    .orderByDesc("extract_time"));
            String expertInformation = extractMonitoringList.get(0).getExpertInformation();
            ExtractRuleBeginVo beginVo = JSONObject.parseObject(expertInformation, ExtractRuleBeginVo.class);
            expertId=beginVo.getExpertId();
            expertInformationSheetDetailVo = toExpertVo(expertId);
        }else {
            //校验重新抽取专家的次数
//        Assert.isTrue(Integer.parseInt(extractExpert.getAgainExtractNum())<3,"重新抽取次数已用完");
            extractExpert.setAgainExtractNum(String.valueOf(Integer.parseInt(extractExpert.getAgainExtractNum())+1));
            extractExpertService.updateById(extractExpert);
            expertInformationSheetDetailVo = toExpertVo(expertId);
            //新增重新抽取专家监控记录
            ExtractRuleBeginVo beginVo = new ExtractRuleBeginVo();
            beginVo.setExpertId(expertInformationSheetDetailVo.getExpertId());
            String expertInformation = JSON.toJSONString(beginVo);
            ExtractMonitoringRuleDto ruleDto = new ExtractMonitoringRuleDto();
            ruleDto.setExtractType(extractRule.getExtractType());
            ruleDto.setExtractRuleDesc(!extractRule.getExtractType().equals(ExtractRule.EXTRACT_TYPE_CONDITION)?expertInformationSheetDetailVo.getExpertName():null);
            String ruleInformation = JSON.toJSONString(ruleDto);
            extractMonitoringMapper.insert(new ExtractMonitoring(IdUtils.snowId(), null, null, reviewTaskDetailVo.getReviewTaskId(), null, ruleInformation, expertInformation,
                    LocalDateTime.now(), null, ExtractMonitoring.EXTRACT_TYPE_EXCHANGE, ExtractMonitoring.EXTRACT_TYPE_AGAIN, String.valueOf(SecurityUtils.getDeptId()), SecurityUtils.getNickName(), "1", ExtractExpert.DELETE_STATUS_NORMAL,extractExpert.getExtractExpertId()));

        }
        return  expertInformationSheetDetailVo;
    }

    /**
     * 未抽取专家
     * @param dto
     * @return 未抽取的专家id
     */
    public List<Long> residueExpert(ExchangeExpertDto dto) {
        ExtractExpert extractExpert = extractExpertService.getById(dto.getExtractExpertId());
        //专家的规则
        ExtractRule extractRule = extractRuleMapper.selectById(extractExpert.getExtractRuleId());
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(dto.getReviewTaskId());
        //已抽取出的专家id
        List<Long> collectExtractId = reviewTaskDetailVo.getExtractExpertList().stream()
                .map(ExtractExpertDetailVo::getExpertId).collect(Collectors.toList());
        //三方机构或大数据局下的专家
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        LambdaQueryWrapper<OrganizationManagement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrganizationManagement::getDeptId,deptId);
        OrganizationManagement organizationManagement = organizationManagementMapper.selectOne(queryWrapper);
        Long ormId = null;
        List<ExpertInformationSheet> sheetList;
        if (StringUtils.isNotNull(organizationManagement)) {
            ormId = organizationManagement.getOrmId();
            List<ExpertInformationSheet> ormIdList = expertInformationSheetService.lambdaQuery().eq(ExpertInformationSheet::getOrmId, ormId)
                    .eq(ExpertInformationSheet::getDelFlag, ExtractExpert.DELETE_STATUS_NORMAL).list();
            sheetList=ormIdList;
        }else {
            List<ExpertInformationSheet> DataList = expertInformationSheetService.lambdaQuery().isNull(ExpertInformationSheet::getOrmId)
                    .eq(ExpertInformationSheet::getDelFlag,ExtractExpert.DELETE_STATUS_NORMAL).list();
            sheetList=DataList;
        }
        //返回未抽取的专家
        Assert.isTrue(StringUtils.isNotEmpty(sheetList),"未找到专家");
        List<Long> sheetIdList = sheetList.stream().map(ExpertInformationSheet::getExpertId).collect(Collectors.toList());
        List<Long> collect = sheetIdList.stream().filter(s -> !collectExtractId.contains(s)).collect(Collectors.toList());
        return collect;
    }
    /**
     *
     * @param dto  评审任务id
     * @return
     */
    @Override
    public ExpertInformationSheetDetailVo selectExchangeExpert(ExchangeExpertDto dto) {
        ExtractExpert extractExpert = extractExpertService.getById(dto.getExtractExpertId());
        ExtractRule extractRule = extractRuleMapper.selectById(extractExpert.getExtractRuleId());
        Long expertId = null;
        List<Long> collect =residueExpert(dto);
        //条件抽取的筛选条件
        List<ExpertRuleDesc> ruleDescList = expertRuleDescService.lambdaQuery().eq(ExpertRuleDesc::getExtractId, extractRule.getExtractId()).list();
        String extractType = extractRule.getExtractType();
        //已抽取出的专家id
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(dto.getReviewTaskId());
        List<Long> collectExtractId = reviewTaskDetailVo.getExtractExpertList().stream()
                .map(ExtractExpertDetailVo::getExpertId).collect(Collectors.toList());
        //条件抽取
        if(ExtractRule.EXTRACT_TYPE_CONDITION.equals(extractType)){
            Assert.isTrue(StringUtils.isNotEmpty(ruleDescList),"条件抽取未找到筛选条件");
            ExpertRuleDesc expertRuleDesc = ruleDescList.get(0);
            //解析条件抽取
            ExpertInformationSheetDto expertInformationSheetDto = new ExpertInformationSheetDto();
            expertInformationSheetDto.setSex(expertRuleDesc.getSex()!=null?expertRuleDesc.getSex():null);
            expertInformationSheetDto.setPoliticalOutlook(expertRuleDesc.getPoliticalOutLook()!=null?expertRuleDesc.getPoliticalOutLook():null);
            expertInformationSheetDto.setStartAge(expertRuleDesc.getStartAge()!=null?expertRuleDesc.getStartAge():null);
            expertInformationSheetDto.setEndAge(expertRuleDesc.getEndAge()!=null?expertRuleDesc.getEndAge():null);
            expertInformationSheetDto.setEqualAge(expertRuleDesc.getEqualAge()!=null?expertRuleDesc.getEqualAge():null);
            String major = expertRuleDesc.getMajor();
            String areasOfExpertise = expertRuleDesc.getAreasOfExpertise();
            String qualifications = expertRuleDesc.getQualifications();
            String technicalTitles = expertRuleDesc.getTechnicalTitles();
            if(StringUtils.isNotEmpty(major)){
                    String[] split = major.split(",");
                    List<String> stringist = Arrays.asList(split);
                    expertInformationSheetDto.setMajor(stringist!=null?stringist:null);

            }
            if(StringUtils.isNotEmpty(areasOfExpertise)){
                    String[] split = areasOfExpertise.split(",");
                    List<String> stringist = Arrays.asList(split);
                    expertInformationSheetDto.setAreasOfExpertise(stringist!=null?stringist:null);

            }
            if(StringUtils.isNotEmpty(qualifications)){
                    String[] split = qualifications.split(",");
                    List<String> stringist = Arrays.asList(split);
                    expertInformationSheetDto.setQualifications(stringist!=null?stringist:null);

            }
            if(StringUtils.isNotEmpty(technicalTitles)){
                    String[] split = technicalTitles.split(",");
                    List<String> stringist = Arrays.asList(split);
                    expertInformationSheetDto.setTechnicalTitles(stringist!=null?stringist:null);


            }
            expertInformationSheetDto.setExpertId(collect);
            List<Long> conditionSelect = expertInformationSheetService.conditionSelect(expertInformationSheetDto,collectExtractId);
            if(StringUtils.isNotEmpty(conditionSelect)){
                List<Long> expertIdList = getRandomThreeInfoList(conditionSelect, 1);
                Assert.isTrue(StringUtils.isNotEmpty(expertIdList),"从查询结果中未找到该专家");
                expertId = expertIdList.get(0);
            }
        }
        if(ExtractRule.EXTRACT_TYPE_RANDOM.equals(extractType)){
            if(RoleUtil.getUserRole(Constants.ROLE_TYPE_BIGDATA)){
                List<Long> randomOneList = expertInformationSheetService.selectRandomOne("1", null, collect,collectExtractId);
                if(StringUtils.isNotEmpty(randomOneList)){
                    expertId = randomOneList.get(0);
                }
            }else if(RoleUtil.getUserRole(Constants.ROLE_TYPE_THIRD)){
                Long deptId = SecurityUtils.getLoginUser().getDeptId();
                List<OrganizationManagement> organizationManagementList = organizationManagementService.lambdaQuery().eq(OrganizationManagement::getDeptId, deptId).list();
                Assert.isTrue(StringUtils.isNotEmpty(organizationManagementList),"该用户未绑定三方机构：用户的部门需绑定一个三方机构部门！！");
                List<Long> randomOneList = expertInformationSheetService.selectRandomOne("1", organizationManagementList.get(0).getOrmId(), collect,collectExtractId);
                if(StringUtils.isNotEmpty(randomOneList)){
                    expertId = randomOneList.get(0);
                }
            }

        }
        ExpertInformationSheetDetailVo expertInformationSheetDetailVo = new ExpertInformationSheetDetailVo();
        //重新抽取达到3次数返回更换回显的专家信息
        if(extractExpert.getAgainExtractNum().equals("3")){
            List<ExtractMonitoring> extractMonitoringList = extractMonitoringMapper.selectList(new QueryWrapper<ExtractMonitoring>()
                    .eq("extract_expert_id ", extractExpert.getExtractExpertId())
                    .orderByDesc("extract_time"));
            String expertInformation = extractMonitoringList.get(0).getExpertInformation();
            ExtractRuleBeginVo beginVo = JSONObject.parseObject(expertInformation, ExtractRuleBeginVo.class);
            expertId=beginVo.getExpertId();
            expertInformationSheetDetailVo = toExpertVo(expertId);
        }else {
            //校验重新抽取专家的次数
//        Assert.isTrue(Integer.parseInt(extractExpert.getAgainExtractNum())<3,"重新抽取次数已用完");
            extractExpert.setAgainExtractNum(String.valueOf(Integer.parseInt(extractExpert.getAgainExtractNum())+1));
            extractExpertService.updateById(extractExpert);
            expertInformationSheetDetailVo = toExpertVo(expertId);
            //新增重新抽取专家监控记录
            ExtractRuleBeginVo beginVo = new ExtractRuleBeginVo();
            beginVo.setExpertId(expertInformationSheetDetailVo.getExpertId());
            String expertInformation = JSON.toJSONString(beginVo);
            ExtractMonitoringRuleDto ruleDto = new ExtractMonitoringRuleDto();
            ruleDto.setExtractType(extractRule.getExtractType());
            ruleDto.setExtractRuleDesc(!extractRule.getExtractType().equals(ExtractRule.EXTRACT_TYPE_CONDITION)?expertInformationSheetDetailVo.getExpertName():null);
            String ruleInformation = JSON.toJSONString(ruleDto);
            extractMonitoringMapper.insert(new ExtractMonitoring(IdUtils.snowId(), null, null, reviewTaskDetailVo.getReviewTaskId(), null, ruleInformation, expertInformation,
                    LocalDateTime.now(), null, ExtractMonitoring.EXTRACT_TYPE_EXCHANGE, ExtractMonitoring.EXTRACT_TYPE_AGAIN, String.valueOf(SecurityUtils.getDeptId()), SecurityUtils.getNickName(), "1", ExtractExpert.DELETE_STATUS_NORMAL,extractExpert.getExtractExpertId()));

        }
        return  expertInformationSheetDetailVo;
    }

    public ExpertInformationSheetDetailVo toExpertVo(Long expertId){
        ExpertInformationSheetDetailVo expertInformationSheetDetailVo = expertInformationSheetService.selectExpertInformationSheetByExpertId(expertId);
        expertInformationSheetDetailVo.setMajor(expertInformationSheetDetailVo.getMajor()!=null?dictDataService.selectDictLabel("major",expertInformationSheetDetailVo.getMajor()):null);
        expertInformationSheetDetailVo.setEducation(expertInformationSheetDetailVo.getEducation()!=null?dictDataService.selectDictLabel("education_background",expertInformationSheetDetailVo.getEducation()):null);
        expertInformationSheetDetailVo.setAreasOfExpertise(expertInformationSheetDetailVo.getAreasOfExpertise()!=null?dictDataService.selectDictLabel("areas_of_expertise",expertInformationSheetDetailVo.getAreasOfExpertise()):null);
        if(StringUtils.isNotEmpty(expertInformationSheetDetailVo.getQualifications())){
            List<ProfessionalQualification> qualificationList = expertInformationSheetDetailVo.getQualifications();
            List<String> stringList = qualificationList.stream().map(ProfessionalQualification::getQualificationName).collect(Collectors.toList());
            List<String> dictLabelList = new ArrayList<>();
            stringList.stream().forEach(s->{
                dictLabelList.add(dictDataService.selectDictLabel("professional_type", s));
            });
            expertInformationSheetDetailVo.setQualificationsName(StringUtils.join(dictLabelList,","));
        }
        if(StringUtils.isNotEmpty(expertInformationSheetDetailVo.getTechnicalTitles())){
            List<TechnicalTitle> technicalTitlesList = expertInformationSheetDetailVo.getTechnicalTitles();
            List<String> jobList = technicalTitlesList.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());
            List<String> jobLabel = new ArrayList<>();
            jobList.stream().forEach(s->{
                jobLabel.add(dictDataService.selectDictLabel("technical_type", s));
            });
            expertInformationSheetDetailVo.setTechnicalTitlesName(StringUtils.join(jobLabel,","));
        }
        return expertInformationSheetDetailVo;
    }
    /**
     *
     * @param dto  评审任务id
     * @return
     */
    @Override
    public ExpertInformationSheetDetailVo selectExchangeExpertInfo(ExchangeExpertDto dto) {
        ExtractExpert extractExpert = extractExpertService.getById(dto.getExtractExpertId());
        ExtractRule extractRule = extractRuleMapper.selectById(extractExpert.getExtractRuleId());
        List<Long> collect =residueExpert(dto);
        //条件抽取的筛选条件
        List<ExpertRuleDesc> ruleDescList = expertRuleDescService.lambdaQuery().eq(ExpertRuleDesc::getExtractId, extractRule.getExtractId()).list();
        String extractType = extractRule.getExtractType();
        Long expertId = null;
        //已抽取出的专家id
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(dto.getReviewTaskId());
        List<Long> collectExtractId = reviewTaskDetailVo.getExtractExpertList().stream()
                .map(ExtractExpertDetailVo::getExpertId).collect(Collectors.toList());
        //条件抽取
        if(ExtractRule.EXTRACT_TYPE_CONDITION.equals(extractType)){
            Assert.isTrue(StringUtils.isNotEmpty(ruleDescList),"条件抽取未找到筛选条件");
            ExpertRuleDesc expertRuleDesc = ruleDescList.get(0);
            //解析条件抽取
            ExpertInformationSheetDto expertInformationSheetDto = new ExpertInformationSheetDto();
            expertInformationSheetDto.setSex(expertRuleDesc.getSex()!=null?expertRuleDesc.getSex():null);
            expertInformationSheetDto.setPoliticalOutlook(expertRuleDesc.getPoliticalOutLook()!=null?expertRuleDesc.getPoliticalOutLook():null);
            expertInformationSheetDto.setStartAge(expertRuleDesc.getStartAge()!=null?expertRuleDesc.getStartAge():null);
            expertInformationSheetDto.setEndAge(expertRuleDesc.getEndAge()!=null?expertRuleDesc.getEndAge():null);
            expertInformationSheetDto.setEqualAge(expertRuleDesc.getEqualAge()!=null?expertRuleDesc.getEqualAge():null);
            String major = expertRuleDesc.getMajor();
            String areasOfExpertise = expertRuleDesc.getAreasOfExpertise();
            String qualifications = expertRuleDesc.getQualifications();
            String technicalTitles = expertRuleDesc.getTechnicalTitles();
            if(StringUtils.isNotEmpty(major)){
                String[] split = major.split(",");
                List<String> stringist = Arrays.asList(split);
                expertInformationSheetDto.setMajor(stringist!=null?stringist:null);

            }
            if(StringUtils.isNotEmpty(areasOfExpertise)){
                String[] split = areasOfExpertise.split(",");
                List<String> stringist = Arrays.asList(split);
                expertInformationSheetDto.setAreasOfExpertise(stringist!=null?stringist:null);

            }
            if(StringUtils.isNotEmpty(qualifications)){
                String[] split = qualifications.split(",");
                List<String> stringist = Arrays.asList(split);
                expertInformationSheetDto.setQualifications(stringist!=null?stringist:null);

            }
            if(StringUtils.isNotEmpty(technicalTitles)){
                String[] split = technicalTitles.split(",");
                List<String> stringist = Arrays.asList(split);
                expertInformationSheetDto.setTechnicalTitles(stringist!=null?stringist:null);


            }
            expertInformationSheetDto.setExpertId(collect);
            List<Long> conditionSelect = expertInformationSheetService.conditionSelect(expertInformationSheetDto,collectExtractId);
            if(StringUtils.isNotEmpty(conditionSelect)){
                List<Long> expertIdList = getRandomThreeInfoList(conditionSelect, 1);
                Assert.isTrue(StringUtils.isNotEmpty(expertIdList),"从查询结果中未找到该专家");
                expertId = expertIdList.get(0);
            }
        }
        if(ExtractRule.EXTRACT_TYPE_RANDOM.equals(extractType)){
            if(RoleUtil.getUserRole(Constants.ROLE_TYPE_BIGDATA)){
                List<Long> randomOneList = expertInformationSheetService.selectRandomOne("1", null, collect,collectExtractId);
                if(StringUtils.isNotEmpty(randomOneList)){
                    expertId = randomOneList.get(0);
                }
            }else if(RoleUtil.getUserRole(Constants.ROLE_TYPE_THIRD)){
                Long deptId = SecurityUtils.getLoginUser().getDeptId();
                List<OrganizationManagement> organizationManagementList = organizationManagementService.lambdaQuery().eq(OrganizationManagement::getDeptId, deptId).list();
                Assert.isTrue(StringUtils.isNotEmpty(organizationManagementList),"该用户未绑定三方机构：用户的部门需绑定一个三方机构部门！！");
                List<Long> randomOneList = expertInformationSheetService.selectRandomOne("1", organizationManagementList.get(0).getOrmId(), collect,collectExtractId);
                if(StringUtils.isNotEmpty(randomOneList)){
                    expertId = randomOneList.get(0);
                }
            }

        }
        if(StringUtils.isNotNull(expertId)){
            ExpertInformationSheetDetailVo expertInformationSheetDetailVo = expertInformationSheetService.selectExpertInformationSheetByExpertId(expertId);
            expertInformationSheetDetailVo.setMajor(expertInformationSheetDetailVo.getMajor()!=null?dictDataService.selectDictLabel("major",expertInformationSheetDetailVo.getMajor()):null);
            expertInformationSheetDetailVo.setEducation(expertInformationSheetDetailVo.getEducation()!=null?dictDataService.selectDictLabel("education_background",expertInformationSheetDetailVo.getEducation()):null);
            expertInformationSheetDetailVo.setAreasOfExpertise(expertInformationSheetDetailVo.getAreasOfExpertise()!=null?dictDataService.selectDictLabel("areas_of_expertise",expertInformationSheetDetailVo.getAreasOfExpertise()):null);
            if(StringUtils.isNotEmpty(expertInformationSheetDetailVo.getQualifications())){
                List<ProfessionalQualification> qualificationList = expertInformationSheetDetailVo.getQualifications();
                List<String> stringList = qualificationList.stream().map(ProfessionalQualification::getQualificationName).collect(Collectors.toList());
                List<String> dictLabelList = new ArrayList<>();
                stringList.stream().forEach(s->{
                    dictLabelList.add(dictDataService.selectDictLabel("professional_type", s));
                });
                expertInformationSheetDetailVo.setQualificationsName(StringUtils.join(dictLabelList,","));
            }
            if(StringUtils.isNotEmpty(expertInformationSheetDetailVo.getTechnicalTitles())){
                List<TechnicalTitle> technicalTitlesList = expertInformationSheetDetailVo.getTechnicalTitles();
                List<String> jobList = technicalTitlesList.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());
                List<String> jobLabel = new ArrayList<>();
                jobList.stream().forEach(s->{
                    jobLabel.add(dictDataService.selectDictLabel("technical_type", s));
                });
                expertInformationSheetDetailVo.setTechnicalTitlesName(StringUtils.join(jobLabel,","));
            }
            return expertInformationSheetDetailVo;
        }
        return  null;
    }

    @Override
    public ExpertInformationSheetDetailVo exchangeExpert(Long reviewTaskId,Long expertId,Long extractExpertId) {
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(reviewTaskId);
        ExtractExpert extractExpert = extractExpertService.getById(extractExpertId);
        //重新抽取达到3次数返回更换回显的专家信息
        ExpertInformationSheetDetailVo expertInformationSheetDetailVo = new ExpertInformationSheetDetailVo();
        if(extractExpert.getAgainExtractNum().equals("3")){
            List<ExtractMonitoring> extractMonitoringList = extractMonitoringMapper.selectList(new QueryWrapper<ExtractMonitoring>()
                    .eq("extract_expert_id ", extractExpertId)
                    .orderByDesc("extract_time"));
            String expertInformation = extractMonitoringList.get(0).getExpertInformation();
            ExtractRuleBeginVo beginVo = JSONObject.parseObject(expertInformation, ExtractRuleBeginVo.class);
            expertId=beginVo.getExpertId();
            expertInformationSheetDetailVo=toExpertVo(expertId);
        }else {
            //校验重新抽取专家的次数
//        Assert.isTrue(Integer.parseInt(extractExpert.getAgainExtractNum())<3,"重新抽取次数已用完");
            extractExpert.setAgainExtractNum(String.valueOf(Integer.parseInt(extractExpert.getAgainExtractNum())+1));
            extractExpertService.updateById(extractExpert);
            expertInformationSheetDetailVo=toExpertVo(expertId);
            //新增重新抽取专家监控记录
            ExtractRuleBeginVo beginVo = new ExtractRuleBeginVo();
            beginVo.setExpertId(expertInformationSheetDetailVo.getExpertId());
            String expertInformation = JSON.toJSONString(beginVo);
            ExtractMonitoringRuleDto ruleDto = new ExtractMonitoringRuleDto();
            ruleDto.setExtractType(ExtractRule.EXTRACT_TYPE_APPOINT);
            ruleDto.setExtractRuleDesc(expertInformationSheetDetailVo.getExpertName()!=null?expertInformationSheetDetailVo.getExpertName():null);
            String ruleInformation = JSON.toJSONString(ruleDto);
            extractMonitoringMapper.insert(new ExtractMonitoring(IdUtils.snowId(), null, null, reviewTaskDetailVo.getReviewTaskId(), null, ruleInformation, expertInformation,
                    LocalDateTime.now(), null, ExtractMonitoring.EXTRACT_TYPE_EXCHANGE, ExtractMonitoring.EXTRACT_TYPE_AGAIN, String.valueOf(SecurityUtils.getDeptId()), SecurityUtils.getNickName(), "1", ExtractExpert.DELETE_STATUS_NORMAL,extractExpert.getExtractExpertId()));
        }
        return expertInformationSheetDetailVo;
    }
    @Override
    public List<ExpertInformationSheetDetailVo> exchangeExpertAssignList(Long reviewTaskId) {
        //三方机构或大数据局下的专家
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        LambdaQueryWrapper<OrganizationManagement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrganizationManagement::getDeptId,deptId);
        OrganizationManagement organizationManagement = organizationManagementMapper.selectOne(queryWrapper);
        Long ormId = null;
        List<ExpertInformationSheet> sheetList;
        if (StringUtils.isNotNull(organizationManagement)) {
            ormId = organizationManagement.getOrmId();
            List<ExpertInformationSheet> ormIdList = expertInformationSheetService.lambdaQuery().eq(ExpertInformationSheet::getOrmId, ormId)
                    .eq(ExpertInformationSheet::getDelFlag, ExtractExpert.DELETE_STATUS_NORMAL).list();
            sheetList=ormIdList;
        }else {
            List<ExpertInformationSheet> DataList = expertInformationSheetService.lambdaQuery().isNull(ExpertInformationSheet::getOrmId)
                    .eq(ExpertInformationSheet::getDelFlag,ExtractExpert.DELETE_STATUS_NORMAL).list();
            sheetList=DataList;
        }
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(reviewTaskId);
        List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
        List<ExpertInformationSheet> expertInformationList = new ArrayList<>();
        extractExpertList.stream().forEach(s->{
            ExpertInformationSheet expertInformationSheet = expertInformationSheetService.getById(s.getExpertId());
            expertInformationList.add(expertInformationSheet);
        });
        //返回未抽取的专家
        Assert.isTrue(StringUtils.isNotEmpty(sheetList),"未找到专家");
        List<ExpertInformationSheet> collect = sheetList.stream().filter(s -> !expertInformationList.contains(s)).collect(Collectors.toList());
        List<Long> IdList = collect.stream().map(ExpertInformationSheet::getExpertId).collect(Collectors.toList());
        List<ExpertInformationSheetDetailVo> list = new ArrayList<>();
        IdList.stream().forEach(expertId->{
            ExpertInformationSheetDetailVo expertInformationSheetDetailVo = expertInformationSheetService.selectExpertInformationSheetByExpertId(expertId);
            expertInformationSheetDetailVo.setMajor(expertInformationSheetDetailVo.getMajor()!=null?dictDataService.selectDictLabel("major",expertInformationSheetDetailVo.getMajor()):null);
            expertInformationSheetDetailVo.setEducation(expertInformationSheetDetailVo.getEducation()!=null?dictDataService.selectDictLabel("education_background",expertInformationSheetDetailVo.getEducation()):null);
            expertInformationSheetDetailVo.setAreasOfExpertise(expertInformationSheetDetailVo.getAreasOfExpertise()!=null?dictDataService.selectDictLabel("areas_of_expertise",expertInformationSheetDetailVo.getAreasOfExpertise()):null);
            if(StringUtils.isNotEmpty(expertInformationSheetDetailVo.getQualifications())){
                List<ProfessionalQualification> qualificationList = expertInformationSheetDetailVo.getQualifications();
                List<String> stringList = qualificationList.stream().map(ProfessionalQualification::getQualificationName).collect(Collectors.toList());
                List<String> dictLabelList = new ArrayList<>();
                stringList.stream().forEach(s->{
                    dictLabelList.add(dictDataService.selectDictLabel("professional_type", s));
                });
                expertInformationSheetDetailVo.setQualificationsName(StringUtils.join(dictLabelList,","));
            }
            if(StringUtils.isNotEmpty(expertInformationSheetDetailVo.getTechnicalTitles())){
                List<TechnicalTitle> technicalTitlesList = expertInformationSheetDetailVo.getTechnicalTitles();
                List<String> jobList = technicalTitlesList.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());
                List<String> jobLabel = new ArrayList<>();
                jobList.stream().forEach(s->{
                    jobLabel.add(dictDataService.selectDictLabel("technical_type", s));
                });
                expertInformationSheetDetailVo.setTechnicalTitlesName(StringUtils.join(jobLabel,","));
            }
            list.add(expertInformationSheetDetailVo);
        });

        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult exchangeExpertAssign(ExchangeExpertAssignDto dto) {
        ExtractExpert extractExpert = extractExpertService.getById(dto.getExtractExpertId());
        ReviewTask reviewTask = reviewTaskService.getById(dto.getReviewTaskId());
        Long expertId = dto.getExpertId();
        Long reviewTaskId = dto.getReviewTaskId();
        //校验更换专家的次数
        Assert.isTrue(Integer.parseInt(extractExpert.getExchangeNum())<3,"更换专家次数已用完");
        //更换专家生成该评审任务进程
        ExpertInformationSheet expertInformationSheetOld = expertInformationSheetService.getById(extractExpert.getExpertId());
        ExpertInformationSheet expertInformationSheetNew = expertInformationSheetService.getById(expertId);
        expertCourseService.save(new ExpertCourse(IdUtils.snowId(),reviewTaskId,SecurityUtils.getNickName()
                +"将"+expertInformationSheetOld.getExpertName()+"更换为"+expertInformationSheetNew.getExpertName(),LocalDateTime.now()));
        //方案评审
        if(ReviewTask.REVIEW_TYPE_PROGRAMME.equals(reviewTask.getReviewType())){
            //原专家的审核进程删除，新专家增加接受任务待接受审核进程
            ProjectManagementDetailsVo managementDetailsVo = projectManagementService.selectProjectManagementListByReviewIds(reviewTaskId);
            //更换专家：项目在意见汇总时不能更换专家,清理抽取监控缓存数据
            if(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode().equals(managementDetailsVo.getNode())){
                List<ExtractMonitoring> extractMonitoringList = extractMonitoringMapper.selectList(new QueryWrapper<ExtractMonitoring>()
                        .eq("review_task_id", reviewTask.getReviewTaskId())
                        .isNull("task_name"));
                List<Long> collect = extractMonitoringList.stream().map(ExtractMonitoring::getExtractMonitoringId).collect(Collectors.toList());
                if(StringUtils.isNotEmpty(collect)){
                    extractMonitoringMapper.deleteBatchIds(collect);
                }
                return AjaxResult.error("意见汇总时不能更换专家");
            }
            List<Approval> list = approvalService.lambdaQuery().eq(Approval::getProjectId, managementDetailsVo.getProId())
                    .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_EXPERT)
                    .eq(Approval::getExpertId, extractExpert.getExpertId())
                    .eq(Approval::getDelFlag,ExtractExpert.DELETE_STATUS_NORMAL).list();
            //获取专家在线预审或重新预审的记录
            List<Approval> approvals = list.stream().filter(s -> s.getApprovalNode().equals(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode())
                    ||s.getApprovalNode().equals(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getNode()))
                    .sorted(Comparator.comparing(Approval::getCreateTime).reversed()).collect(Collectors.toList());
            List<Long> approvalIds = list.stream().map(Approval::getApprovalId).collect(Collectors.toList());
            if(StringUtils.isNotEmpty(approvals)){
                //之前的项目评审相同时间的重新预审或者在线预审保留
                List<Approval> projectList = approvalService.lambdaQuery().eq(Approval::getProjectId, managementDetailsVo.getProId())
                        .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_PROJECT_MANAGE)
                        .eq(Approval::getApprovalNode, ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode())
                        .eq(Approval::getDelFlag,ExtractExpert.DELETE_STATUS_NORMAL)
                        .orderByDesc(Approval::getCreateTime).list();
                List<Long> arrayList = new ArrayList<>();
                projectList.stream().forEach(a->{
                    approvals.stream().forEach(b->{
                        if(a.getCreateTime().equals(b.getCreateTime())&&b.getApprovalNode().equals(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode())
                                ||a.getCreateTime().equals(b.getCreateTime())&&b.getApprovalNode().equals(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getNode())){
                            arrayList.add(b.getApprovalId());
                        }
                    });
                });
                approvalIds.removeAll(arrayList);
                //当前项目审核相同的专家在线预审或者重新预审记录及其他接口的记录删除
                List<Approval> collect = approvals.stream().filter(s -> s.getCreateTime().equals(projectList.get(0).getCreateTime())).collect(Collectors.toList());
                if(StringUtils.isNotEmpty(collect)){
                    approvalIds.add(collect.get(0).getApprovalId());
                }
            }
            approvalService.removeByIds(approvalIds);
            //更换专家id
            extractExpert.setExpertId(expertId);
            //更换专家后抽取表状态初始化
            extractExpert.setRefuseReason(null);
            extractExpert.setApplyCancel(ExtractExpert.APPLY_NOT_CANCEL);
            extractExpert.setDealTime(null);
            extractExpert.setDelFlag(ExtractExpert.DELETE_STATUS_NORMAL);
            extractExpert.setExchangeNum(String.valueOf(Integer.parseInt(extractExpert.getExchangeNum())+1));
            if(!extractExpert.getAgainExtractNum().equals("3")){
                extractExpert.setAgainExtractNum("0");
            }
            //TODO: 更换专家-新专家更换后处于旧专家该节点专家的初始状态，更新抽取表状态、评审任务状态
            //接受任务：新增专家接受任务待接受进程
            if(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode().equals(reviewTask.getNode()) ||
                    ProjectStatusEnum.ACCEPT_TASKED.get().getNode().equals(reviewTask.getNode()) ){
                //评审任务状态为待接受
                reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_ACCEPT);
                extractExpert.setExtractNode(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus());
                extractExpert.setStatus(ExtractExpert.STATUS_NOT_ACCEPT);
                extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_TO_BE_ACCEPT);
                approvalService.save(new Approval(IdUtils.snowId(),managementDetailsVo.getProId(),ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStage(),
                        ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),null,ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,expertId,null));
            //在线预审：新增专家已接受任务进程、在线预审待审核进程
            }else if(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode().equals(reviewTask.getNode())
                        ||ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getNode().equals(reviewTask.getNode())){
                LocalDateTime localDateTime=null;
                //获取专家最新在线预审的时间
                List<Approval> onlineApprovalList = approvalService.lambdaQuery().eq(Approval::getProjectId, managementDetailsVo.getProId())
                        .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_PROJECT_MANAGE)
                        .eq(Approval::getApprovalNode, ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode())
                        .eq(Approval::getDelFlag,ExtractExpert.DELETE_STATUS_NORMAL)
                        .orderByDesc(Approval::getCreateTime).list();
                if(StringUtils.isNotEmpty(onlineApprovalList)){
                    List<Approval> collect = onlineApprovalList.stream()
                            .sorted(Comparator.comparing(Approval::getCreateTime).reversed()).collect(Collectors.toList());
                    localDateTime=collect.get(0).getCreateTime();
                }
                //评审任务状态为已接受
                reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_ACCEPTED);
                extractExpert.setExtractNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                extractExpert.setStatus(ExtractExpert.STATUS_NOT_APPROVAL);
                extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_ACCEPT);
                approvalService.save(new Approval(IdUtils.snowId(),managementDetailsVo.getProId(),ProjectStatusEnum.ACCEPT_TASKED.get().getStage(),
                        ProjectStatusEnum.ACCEPT_TASKED.get().getNode(),LocalDateTime.now().minus(1, ChronoUnit.SECONDS),LocalDateTime.now(),null,ProjectStatusEnum.ACCEPT_TASKED.get().getStatus(),
                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,expertId,null));
                approvalService.save(new Approval(IdUtils.snowId(),managementDetailsVo.getProId(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage(),
                        ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                        "/",null, null,null,localDateTime ,Approval.APPROVAL_TYPE_EXPERT,expertId,null));
            //现场论证：新增专家已接受任务进程、在线预审已审核进程、现场论证待开始
            }else if(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode().equals(reviewTask.getNode())){
                extractExpert.setExtractNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                extractExpert.setStatus(ExtractExpert.STATUS_NOT_START);
                extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_ACCEPT);
                approvalService.save(new Approval(IdUtils.snowId(),managementDetailsVo.getProId(),ProjectStatusEnum.ACCEPT_TASKED.get().getStage(),
                        ProjectStatusEnum.ACCEPT_TASKED.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),null,ProjectStatusEnum.ACCEPT_TASKED.get().getStatus(),
                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,expertId,null));
                approvalService.save(new Approval(IdUtils.snowId(),managementDetailsVo.getProId(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage(),
                        ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),null,ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,expertId,null));
                approvalService.save(new Approval(IdUtils.snowId(),managementDetailsVo.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                        ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,expertId,null));

            }
        //年度评审
        }else {
            Long planId = reviewTask.getPlanId();
            List<Approval> approvalList = approvalService.lambdaQuery().eq(Approval::getExpertId, extractExpert.getExpertId())
                    .eq(Approval::getPlanId, planId)
                    .eq(Approval::getExpertId, extractExpert.getExpertId())
                    .eq(Approval::getDelFlag,ExtractExpert.DELETE_STATUS_NORMAL)
                    .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_EXPERT).list();
            List<Long> approvalIds = approvalList.stream().map(Approval::getApprovalId).collect(Collectors.toList());
            approvalService.removeByIds(approvalIds);
            approvalService.save(new Approval(IdUtils.snowId(),null,ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStage(),
                    ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),SecurityUtils.getNickName(),ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                    "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,expertId,planId));

            extractExpert.setExpertId(expertId);
            //更换专家后抽取表状态初始化
            extractExpert.setExtractNode(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus());
            extractExpert.setStatus(ExtractExpert.STATUS_NOT_ACCEPT);
            extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_TO_BE_ACCEPT);
            extractExpert.setRefuseReason(null);
            extractExpert.setApplyCancel(ExtractExpert.APPLY_NOT_CANCEL);
            extractExpert.setDealTime(null);
            extractExpert.setDelFlag(ExtractExpert.DELETE_STATUS_NORMAL);
            extractExpert.setExchangeNum(String.valueOf(Integer.parseInt(extractExpert.getExchangeNum())+1));
            //评审任务状态为待接受
            reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_ACCEPT);
        }
        //更换规则
        if(StringUtils.isNotEmpty(dto.getExtractType())){
            ExtractRule extractRule = extractRuleService.getById(extractExpert.getExtractRuleId());
            //规则人数为1则更新规则信息
            if(extractRule.getPeopleNumber()==1){
                //如果规则类型为条件抽取，
                if(dto.getExtractType().equals(ExtractRule.EXTRACT_TYPE_CONDITION)){
                //更换前的规则为条件抽取则更新条件描述
                    if(extractRule.getExtractType().equals(ExtractRule.EXTRACT_TYPE_CONDITION)){
                        List<ExpertRuleDesc> ruleDescList = expertRuleDescService.lambdaQuery().eq(ExpertRuleDesc::getExtractId, extractRule.getExtractId()).list();
                        if(StringUtils.isNotEmpty(ruleDescList)){
                            ExpertRuleDesc expertRuleDescOld = ruleDescList.get(0);
                            ExpertRuleDesc ruleDesc = new ExpertRuleDesc();
                            ruleDesc.setExpertRuleDescId(expertRuleDescOld.getExpertRuleDescId());
                            ExpertRuleDesc expertRuleDesc = getExpertRuleDesc(dto.getExpertInformationSheet(), ruleDesc, extractRule);
                            BeanUtils.copyProperties(expertRuleDesc,expertRuleDescOld);
                            expertRuleDescService.updateById(expertRuleDescOld);
                        }
                    //更换前的规则不为条件抽取则新增条件描述
                    }else {
                        ExpertInformationSheetDto expertInformationSheet = dto.getExpertInformationSheet();
                        if(StringUtils.isNotNull(expertInformationSheet)){
                            ExpertRuleDesc expertRuleDesc = new ExpertRuleDesc();
                            ExpertRuleDesc expertRuleDesc1 = getExpertRuleDesc(expertInformationSheet, expertRuleDesc, extractRule);
                            expertRuleDescService.save(expertRuleDesc1);
                        }
                    }

                }
                extractRule.setExtractType(dto.getExtractType());
                extractRule.setExtractRuleDesc(dto.getExtractRuleDesc());
                extractRuleService.updateById(extractRule);
            //规则人数不为1 则新增一条规则信息，之前的规则人数少1
            }else {
                ExtractRule rule = new ExtractRule(IdUtils.snowId(), reviewTask.getReviewTaskId(), dto.getExtractType(), 1, dto.getExtractRuleDesc(), LocalDateTime.now(), LocalDateTime.now());
                extractRuleService.save(rule);
                //更换专家前的抽取规则id
                Long extractRuleId = extractExpert.getExtractRuleId();
                ExtractRule ruleServiceById = extractRuleService.getById(extractRuleId);
                extractExpert.setExtractRuleId(rule.getExtractId());
                extractExpertService.updateById(extractExpert);
                //如果规则类型为条件抽取，新增一条条件描述
                ExpertInformationSheetDto expertInformationSheet = dto.getExpertInformationSheet();
                if(StringUtils.isNotNull(expertInformationSheet)){
                    ExpertRuleDesc expertRuleDesc = new ExpertRuleDesc();
                    ExpertRuleDesc expertRuleDesc1 = getExpertRuleDesc(expertInformationSheet, expertRuleDesc, rule);
                    expertRuleDescService.save(expertRuleDesc1);
                    //如果规则类型为随机抽取或者指定抽取，更改更换前的规则描述
                }else {
                    List<ExtractExpert> expertList = extractExpertService.lambdaQuery().eq(ExtractExpert::getExtractRuleId, extractRuleId).list();
                    List<Long> expertIdList = expertList.stream().map(ExtractExpert::getExpertId).collect(Collectors.toList());
                    List<String> expertNameList = new ArrayList<>();
                    expertIdList.stream().forEach(s->{
                        String expertName = expertInformationSheetService.getById(s).getExpertName();
                        expertNameList.add(expertName);
                    });

                    ruleServiceById.setExtractRuleDesc(String.join(",",expertNameList));
                    ruleServiceById.setExtractType(dto.getExtractType());
                    ruleServiceById.setPeopleNumber(ruleServiceById.getPeopleNumber()-1);
                }

                extractRule.setPeopleNumber(extractRule.getPeopleNumber()-1);
                extractRule.setExtractType(dto.getExtractType());
                extractRuleService.updateById(extractRule);
                //修改人数大于1的抽取规则的描述
                extractRuleService.updateById(ruleServiceById);
            }

        }
        reviewTask.setUpdateTime(LocalDateTime.now());
        reviewTaskService.updateById(reviewTask);
        return AjaxResult.success(extractExpertService.updateById(extractExpert));
    }

    /**
     * ExpertInformationSheetDto对象转化为ExpertRuleDesc
     * @return
     */
   public ExpertRuleDesc getExpertRuleDesc(ExpertInformationSheetDto expertInformationSheet,ExpertRuleDesc expertRuleDesc,ExtractRule extractRule){
       expertRuleDesc.setPoliticalOutLook(expertInformationSheet.getPoliticalOutlook()!=null?expertInformationSheet.getPoliticalOutlook():null);
       expertRuleDesc.setSex(expertInformationSheet.getSex()!=null?expertInformationSheet.getSex():null);
       expertRuleDesc.setExtractId(extractRule.getExtractId());
       expertRuleDesc.setEndAge(expertInformationSheet.getEndAge()!=null?expertInformationSheet.getEndAge():null);
       expertRuleDesc.setStartAge(expertInformationSheet.getStartAge()!=null?expertInformationSheet.getStartAge():null);
       expertRuleDesc.setEqualAge(expertInformationSheet.getEqualAge()!=null?expertInformationSheet.getEqualAge():null);
       List<String> areasOfExpertiseList = expertInformationSheet.getAreasOfExpertise();
       if(StringUtils.isNotEmpty(areasOfExpertiseList)){
           String areasOfExpertise = areasOfExpertiseList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
           expertRuleDesc.setAreasOfExpertise(areasOfExpertise);
       }
       List<String> majorList = expertInformationSheet.getMajor();
       if(StringUtils.isNotEmpty(majorList)){
           String major = majorList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
           expertRuleDesc.setMajor(major);
       }
       List<String> technicalTitlesList = expertInformationSheet.getTechnicalTitles();
       if(StringUtils.isNotEmpty(technicalTitlesList)){
           String technicalTitles = technicalTitlesList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
           expertRuleDesc.setTechnicalTitles(technicalTitles);
       }
       List<String> qualificationsList = expertInformationSheet.getQualifications();
       if(StringUtils.isNotEmpty(qualificationsList)){
           String qualifications = qualificationsList.stream().map(integer -> integer.toString()).collect(Collectors.joining(","));
           expertRuleDesc.setQualifications(qualifications);
       }
       return expertRuleDesc;
   }
    @Override
    public List<ExtractRuleBeginDto> getParameter() {
        ArrayList<ExtractRuleBeginDto> arrayList = new ArrayList<>();
        List<Long> idList = new ArrayList<>();
        idList.add(1502677878439936000L);
        ExpertInformationSheet expertInformationSheet = new ExpertInformationSheet();
        expertInformationSheet.setSex("1");
        ExtractRuleBeginDto extractRuleBeginDto = new ExtractRuleBeginDto();
//        extractRuleBeginDto.setExpertInformationSheet(expertInformationSheet);
        extractRuleBeginDto.setExtractType(ExtractRule.EXTRACT_TYPE_CONDITION);
        extractRuleBeginDto.setExtractRuleDesc("t条件抽取");
        extractRuleBeginDto.setPeopleNumber(1);
        arrayList.add(extractRuleBeginDto);
        ExtractRuleBeginDto extractRuleBeginDto1 = new ExtractRuleBeginDto();
        extractRuleBeginDto1.setPeopleNumber(1);
        extractRuleBeginDto1.setExtractType(ExtractRule.EXTRACT_TYPE_RANDOM);
        extractRuleBeginDto1.setExtractRuleDesc("随机抽取");
        arrayList.add(extractRuleBeginDto1);
        ExtractRuleBeginDto extractRuleBeginDto2 = new ExtractRuleBeginDto();
        extractRuleBeginDto2.setPeopleNumber(1);
        extractRuleBeginDto2.setExtractType(ExtractRule.EXTRACT_TYPE_APPOINT);
        extractRuleBeginDto2.setExtractRuleDesc("指定专家抽取");
        extractRuleBeginDto2.setExpertIdList(idList);
        arrayList.add(extractRuleBeginDto2);
        return arrayList;
    }
}
